using Godot;
using Godot.Collections;
using System;
using Vector2 = Godot.Vector2;

public class EntityData
{
    public int id;
    public String Name;
    public Vector2 Position;

    public Dictionary<String, String> data = new Dictionary<string, string>();
    public Vector2 GetChunkLocation()
    {
        return ((Position / 16).Round() / 16).Round() * new Vector2(1, -1);
    }
    public Dictionary getDict()
    {
        Dictionary dict = new Dictionary();
        dict.Add("Name", Name);
        dict.Add("X", Position.x);
        dict.Add("Y", Position.y);
        if (data.Count > 0) dict.Add("data", data);
        return dict;
    }
    public String toJson()
    {
        return JSON.Print(getDict());
    }
    public EntityData JsonTo(Dictionary dict)
    {
        Name = (String)dict["Name"];
        int x = dict["X"].ToInt();
        int y = dict["Y"].ToInt();
        if (dict.Contains("data")) data = (Dictionary<String, String>)dict["data"];
        return this;
    }
}